Skip to main content

All Questions

2votes
2answers
290views

Pattern for a base class to do pre-validation and/or post-processing on a deriving class's overridden method?

I have the following pattern repeating itself in multiple places: abstract class Database { void connect() { this.setStatus( CONNECTING ) try { await this.realConnect() } catch ...
Mahi's user avatar
  • 406
0votes
3answers
977views

How to handle subclasses needing different method signatures for the overriden function?

I have an abstract class that represents chess pieces, it has an abstract method isMoveValid(Square futurePosition, PieceColor color) which checks if the piece moving to that square is valid or not, ...
Yoh's user avatar
  • 51
1vote
1answer
603views

Strategy Design Pattern vs Inheritance

I have to write a code where i have send some data (call it List of cases) using one of two integration tools (Jitterbit, Mulesoft), with possibility of adding more tools in future. Integration tool ...
user2957592's user avatar
-3votes
1answer
70views

How would you architect a simple cascading style sheet object?

How would you architect a simple cascading stylesheet like inheritance object? For example, I have Apple that extends Fruit. class Fruit { constructor() { this.total = 10; } } ...
1.21 gigawatts's user avatar
1vote
3answers
396views

subclass with no logic of abstract class

I have a class named Change which should be abstract and have some basic methods. I have classes Insert, Update and Delete that extends Change. In the case of Insert, Update I just use extend and add ...
T.S's user avatar
  • 141
0votes
2answers
532views

Design issue with delegation, inheritance and dependency injection

My question relates to usage of delegation together with inheritance and dependency injection. I have a MailerService class that requires a delegate in order to do its job. Furthermore, I have a ...
balteo's user avatar
5votes
4answers
14kviews

Why the industry prefer/use composition over inheritance? [duplicate]

I was having a discussion with few friends about inheritance and composition and what I learnt from that discussion is that the use of inheritance more or less condemned in industry nowadays and ...
Diaufh138's user avatar
1vote
3answers
481views

design pattern for class with data attached

I have a class Tiles that looks something like this: class Tiles { public: void AddTile(int x) { tiles_.push_back(x); } std::vector<int> tiles_; } Now I want to create a class Tiles with ...
hovnatan's user avatar
4votes
2answers
2kviews

Inheritance and factory together?

I have a hierarchical data model and am trying to implement their CRUD operations in my Web Application. Currently I have code inheritance for CRUD operations of my entities (resources) as follows: ...
Siddharth Trikha's user avatar
1vote
2answers
246views

Processing and sending processed data to super from child class constructor

I want to do some initialization in child class constructor and pass result to super(). But Java doesn't allow any processing in child class constructor before super() call. Whats a good way to ...
mzlo's user avatar
  • 141
6votes
7answers
5kviews

Does this code solve the square/rectangle Liskov Substitution Principle example?

I just wanted to check that I understand the LSP correctly and can solve it. I am taking the classic rectangle/square problem and attempting a solution: class Rectangle{ public $width; public $...
user1578653's user avatar
4votes
5answers
2kviews

Inheritance when following the Repository Pattern in PHP

I am trying to build a PHP application using the Repository Pattern but I'm not sure how I should implement the save method. I have an abstract class called ItemRepository which have the following ...
Oskar Persson's user avatar
2votes
2answers
348views

Is this the solution to static inheritance?

I've seen a lot of posts recently on why Singletons should be avoided. However, I can't see any of those problems with the following solution to a common problem: static inheritance. For example, I ...
James Ko's user avatar
1vote
1answer
328views

Adding new functionality to all of shelve.Shelf's subclasses in Python

In order to avoid the overhead associated with the shelve module's writeback option I'm interested in putting together a shelf class that only accepts hashable values, with hashability being a proxy ...
kuzzooroo's user avatar

close